package com.xiaoka.flutter_plugin_gdmap.AMap;

import android.app.Activity;
import android.content.Context;
import android.util.Log;

import com.google.gson.Gson;

import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.StandardMessageCodec;
import io.flutter.plugin.platform.PlatformView;
import io.flutter.plugin.platform.PlatformViewFactory;

/**
 * Copyright (C), 2020 - 2999, Sichuan Xiaoka Technology Co., Ltd.
 *
 * @Description:
 * @Author: lch
 * @Date: 2020/10/23 15:15
 **/
public class AMapPluginFactory extends PlatformViewFactory {

    private final BinaryMessenger mBinaryMessenger;
    private final Activity mActivity;

    public AMapPluginFactory(BinaryMessenger binaryMessenger, Activity activity) {
        super(StandardMessageCodec.INSTANCE);
        mBinaryMessenger = binaryMessenger;
        mActivity = activity;
    }

    @Override
    public PlatformView create(Context context, int viewId, Object object) {
        Gson gson = new Gson();
        AMapBean aMapBean = new AMapBean();
        if (object instanceof String) {
            Log.e("地图~~~~~~~~~~", "create: "+object.toString());
            aMapBean = gson.fromJson(object.toString(), AMapBean.class);
        }
        AMapPluginView aMapPluginView = new AMapPluginView(mBinaryMessenger,mActivity,viewId, context, aMapBean);
        return aMapPluginView;
    }
}
